﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AdmLaboratorios.Business;
using AdmLaboratorios.DTO;

namespace AdmLaboratorios
{
    public partial class frmIRSinOP : Form
    {
        public frmIRSinOP()
        {
            InitializeComponent();
        }

        private void frmIRSinOP_Load(object sender, EventArgs e)
        {
            ReloadOrders();
        }

        private void ReloadOrders()
        {

            gv.DataSource = null;
            gvItems.DataSource = null;

            gv.DataSource = (DataTable)InformesRecepcion.SinOp();
            lblOrdenes.Text = ((DataTable)gv.DataSource).Rows.Count.ToString();
        }

        private void ReloadItems()
        {
            if (gv.SelectedRows.Count == 1)
            {
                gvItems.DataSource = null;
                gvItems.DataSource = InformesRecepcion.GetItemsByIR((int)gv.SelectedRows[0].Cells["Id"].Value);
                lblItems.Text = ((List<InformeRecepcionItemDTO>)gvItems.DataSource).Count.ToString();
            }
        }

        private void btnCerrar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnModificar_Click(object sender, EventArgs e)
        {
            if (gv.SelectedRows.Count == 1)
            {
                var f = FormsFactory.ShowForm<frmIRModificacion>();
                f.SetValues((int)gv.SelectedRows[0].Cells["Id"].Value);
            }
        }

        private void gv_SelectionChanged(object sender, EventArgs e)
        {
            ReloadItems();
        }
    }
}
